﻿using easysmb;
using ExcelConfig;
using ExcelConfig.Config;
using ExcelConfig.StoreAPI;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            if (string.IsNullOrEmpty(AppConfig.Text("验证密码")))
            {
                Console.Write("press you config password: ");
                var pwd = Console.ReadLine();
                if (pwd != null && (pwd = pwd.Trim()) != string.Empty) AppConfig.WriteText("验证密码", pwd);
            }
            var config_path = "./config/smb.config.xlsx";
            if (!Directory.Exists("config")) Directory.CreateDirectory("config");
            if (!File.Exists(config_path)) ConfigStoreAPI.DownloadToFile(AppConfig.Text("配置域"), "smb-test01", config_path).Wait();

            var cfg = new AppConfigFile("config", "smb");
            var a = new EasySMB(cfg.Text("本地地址"));
            a.Login(cfg.Text("本地用户名"), cfg.Text("本地密码"));

            var p = a.GetPath("share");
            using (var f = p.NewFile("wuo.dll"))
            using (var f2 = File.Open("wuo.dll", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                f2.CopyTo(f);
            }

            foreach(var f in a.LoopFiles("share"))
            {
                f.Delete();
            }
        }
    }
}
